package br.com.beautycenter.view;

import br.com.beautycenter.DAO.PersisteFuncionario;
import br.com.beautycenter.ModelosTabela.JTablePanelRenderer;
import br.com.beautycenter.ModelosTabela.TableModelAgenda;
import br.com.beautycenter.bean.Funcionario;
import java.awt.Color;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class AgendaTratamentos extends javax.swing.JFrame {

    PersisteFuncionario persisteFuncionario = new PersisteFuncionario();
    
    Funcionario funcionario = new Funcionario();
    
    TableModelAgenda modelo;
    
    public void preencherComboFuncionario(){
        comboFuncionario.removeAllItems();
        comboFuncionario.addItem("Selecione um funcionário");
        
        for(Funcionario item: persisteFuncionario.retornarFuncionario()){
            comboFuncionario.addItem(item.getNome());
        }
    }

    public void pegarFuncionario(){
        if(comboFuncionario.getSelectedIndex() == 0) {
            funcionario = null;
        }else{
            funcionario = new Funcionario();
            funcionario.setNome(comboFuncionario.getSelectedItem().toString());
            funcionario = persisteFuncionario.retornarFuncionarioPeloNome(funcionario).get(0);
        }
       
    }

    public void configurarTabela(){
        pegarFuncionario();
        modelo = new TableModelAgenda(funcionario, jDate.getDate());
        
        tableAgenda.setModel(modelo);
        
        tableAgenda.setDefaultRenderer(JPanel.class, new JTablePanelRenderer());
        tableAgenda.setRowHeight(40);
    }
    
    public void inserirCores(){
        pegarFuncionario();
        
        if(funcionario == null){
            JOptionPane.showMessageDialog(null, "Selecione um funcionário"); return;
        }else if(jDate.getDate() == null){
            JOptionPane.showMessageDialog(null, "Selecione uma data"); return;
        }else{
            modelo.setFuncionario(funcionario);
            modelo.preecherCoresTabela(jDate.getDate());
            modelo.preencherColuna(jDate.getDate());
            
            //atualiza os nomes da coluna da tabela
            String[] colunas = modelo.getColunas();
            for(int i=1; i<colunas.length; i++){
                tableAgenda.getTableHeader().getColumnModel().getColumn(i).setHeaderValue(colunas[i]);
            }
            repaint();
        }  
    }
    
    public void configuracoesIniciais(){
        preencherComboFuncionario();
        configurarTabela();
    }

    public AgendaTratamentos() {
        initComponents();
        configuracoesIniciais();
        jDate.setDate(new Date());
        
        this.setExtendedState(getExtendedState() | MAXIMIZED_BOTH);//maximiza a tela
        this.pack();
        this.getContentPane().setBackground(Color.WHITE); //muda o fundo para branco
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelPrincipal = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        comboFuncionario = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableAgenda = new javax.swing.JTable();
        jDate = new com.toedter.calendar.JDateChooser();
        jLabel4 = new javax.swing.JLabel();
        btnVisualizar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanelTratamento = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jPanelPilatesCompleto = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanelPilatesVaga = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jPanelAvulso = new javax.swing.JPanel();
        jPanelHorarioVago = new javax.swing.JPanel();
        jPanelLaser1 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("ERP BEAUTY CENTER - Agenda de tratamentos");

        jPanelPrincipal.setBackground(new java.awt.Color(255, 255, 255));
        jPanelPrincipal.setPreferredSize(new java.awt.Dimension(800, 555));

        jLabel3.setText("Profissional");

        tableAgenda.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(tableAgenda);

        jLabel4.setText("Data");

        btnVisualizar.setText("Visualizar");
        btnVisualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVisualizarActionPerformed(evt);
            }
        });

        jPanelTratamento.setBackground(new java.awt.Color(0, 153, 255));
        jPanelTratamento.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanelTratamento.setForeground(new java.awt.Color(0, 153, 255));

        javax.swing.GroupLayout jPanelTratamentoLayout = new javax.swing.GroupLayout(jPanelTratamento);
        jPanelTratamento.setLayout(jPanelTratamentoLayout);
        jPanelTratamentoLayout.setHorizontalGroup(
            jPanelTratamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 24, Short.MAX_VALUE)
        );
        jPanelTratamentoLayout.setVerticalGroup(
            jPanelTratamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Pacote de Tratamento");

        jPanelPilatesCompleto.setBackground(new java.awt.Color(0, 102, 102));
        jPanelPilatesCompleto.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanelPilatesCompleto.setForeground(new java.awt.Color(0, 102, 102));

        javax.swing.GroupLayout jPanelPilatesCompletoLayout = new javax.swing.GroupLayout(jPanelPilatesCompleto);
        jPanelPilatesCompleto.setLayout(jPanelPilatesCompletoLayout);
        jPanelPilatesCompletoLayout.setHorizontalGroup(
            jPanelPilatesCompletoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 24, Short.MAX_VALUE)
        );
        jPanelPilatesCompletoLayout.setVerticalGroup(
            jPanelPilatesCompletoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 17, Short.MAX_VALUE)
        );

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Pilates - Turma Completa");

        jPanelPilatesVaga.setBackground(new java.awt.Color(153, 153, 0));
        jPanelPilatesVaga.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanelPilatesVaga.setForeground(new java.awt.Color(153, 153, 0));

        javax.swing.GroupLayout jPanelPilatesVagaLayout = new javax.swing.GroupLayout(jPanelPilatesVaga);
        jPanelPilatesVaga.setLayout(jPanelPilatesVagaLayout);
        jPanelPilatesVagaLayout.setHorizontalGroup(
            jPanelPilatesVagaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 24, Short.MAX_VALUE)
        );
        jPanelPilatesVagaLayout.setVerticalGroup(
            jPanelPilatesVagaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Pilates - Turma com Vaga");

        jPanelAvulso.setBackground(new java.awt.Color(0, 102, 153));
        jPanelAvulso.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanelAvulso.setForeground(new java.awt.Color(0, 102, 153));

        javax.swing.GroupLayout jPanelAvulsoLayout = new javax.swing.GroupLayout(jPanelAvulso);
        jPanelAvulso.setLayout(jPanelAvulsoLayout);
        jPanelAvulsoLayout.setHorizontalGroup(
            jPanelAvulsoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 24, Short.MAX_VALUE)
        );
        jPanelAvulsoLayout.setVerticalGroup(
            jPanelAvulsoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 17, Short.MAX_VALUE)
        );

        jPanelHorarioVago.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanelHorarioVago.setForeground(new java.awt.Color(240, 240, 240));

        javax.swing.GroupLayout jPanelHorarioVagoLayout = new javax.swing.GroupLayout(jPanelHorarioVago);
        jPanelHorarioVago.setLayout(jPanelHorarioVagoLayout);
        jPanelHorarioVagoLayout.setHorizontalGroup(
            jPanelHorarioVagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 24, Short.MAX_VALUE)
        );
        jPanelHorarioVagoLayout.setVerticalGroup(
            jPanelHorarioVagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 17, Short.MAX_VALUE)
        );

        jPanelLaser1.setBackground(new java.awt.Color(255, 102, 102));
        jPanelLaser1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanelLaser1.setForeground(new java.awt.Color(255, 102, 102));

        javax.swing.GroupLayout jPanelLaser1Layout = new javax.swing.GroupLayout(jPanelLaser1);
        jPanelLaser1.setLayout(jPanelLaser1Layout);
        jPanelLaser1Layout.setHorizontalGroup(
            jPanelLaser1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 24, Short.MAX_VALUE)
        );
        jPanelLaser1Layout.setVerticalGroup(
            jPanelLaser1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("Laser");

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("Horário Vago");

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("Avulso");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelPilatesCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelTratamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelPilatesVaga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6))
                .addGap(51, 51, 51)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelHorarioVago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelAvulso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelLaser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(28, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel5, jLabel6, jLabel7});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanelTratamento, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelPilatesCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelAvulso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelHorarioVago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanelLaser1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelPilatesVaga, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanelPrincipalLayout = new javax.swing.GroupLayout(jPanelPrincipal);
        jPanelPrincipal.setLayout(jPanelPrincipalLayout);
        jPanelPrincipalLayout.setHorizontalGroup(
            jPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPrincipalLayout.createSequentialGroup()
                .addComponent(jScrollPane2)
                .addGap(19, 19, 19))
            .addGroup(jPanelPrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelPrincipalLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comboFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jDate, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnVisualizar))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(766, Short.MAX_VALUE))
        );
        jPanelPrincipalLayout.setVerticalGroup(
            jPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(comboFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4))
                    .addComponent(jDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnVisualizar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 616, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 1309, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVisualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVisualizarActionPerformed
        inserirCores();
    }//GEN-LAST:event_btnVisualizarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnVisualizar;
    private javax.swing.JComboBox comboFuncionario;
    private com.toedter.calendar.JDateChooser jDate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelAvulso;
    private javax.swing.JPanel jPanelHorarioVago;
    private javax.swing.JPanel jPanelLaser1;
    private javax.swing.JPanel jPanelPilatesCompleto;
    private javax.swing.JPanel jPanelPilatesVaga;
    private javax.swing.JPanel jPanelPrincipal;
    private javax.swing.JPanel jPanelTratamento;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tableAgenda;
    // End of variables declaration//GEN-END:variables
}